use alloc::string::{String, ToString};

pub fn read_line(line: &mut String) -> usize {
    line.clear();

    let buf = &mut [0u8];
    let kbd_fd = crate::op::open("/kdriver/kbd".to_string(), crate::op::OpenMode::Read);

    crate::op::read(kbd_fd, buf);

    while buf[0] != b'\n' {
        if buf[0] == 8 {
            if let Some(_) = line.pop() {
                crate::print!("{} {}", 8 as char, 8 as char);
            }
        } else {
            crate::print!("{}", buf[0] as char);
            line.push(buf[0] as char);
        }

        crate::op::read(kbd_fd, buf);
    }

    0
}
